const cloud = require('wx-server-sdk');

cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
});
const db = cloud.database();

// 修改数据库信息云函数入口函数
exports.main = async (event, context) => {
  try {
    const { openId, nickName, avatarUrl } = event.data;
      await db.collection('user').where({
        _openId: openId
      })
        .update({
          data: {
            nickName, 
            avatarUrl
          },
        });
    return {
      success: true,
    };
  } catch (e) {
    return {
      success: false,
      errMsg: e
    };
  }
};
